import React, { Component } from 'react';
import './News_list.css';
import axios from 'axios';
import {List} from 'antd';
import {URL} from "../../constant/Constant";
import {
    SearchWapper,
    SearchName,
    SearchBox,
    ListInfo,
    ListInfoPDF,
    ListInfoPDFButton
} from '../search/DataSearStyle';
import Divider from "antd/lib/divider";


export default class Log extends Component{
    constructor(props){
        super(props);
        this.state = {
        LogData:[],
        }
    }
    componentDidMount(){
        axios({
            method: 'post',
            url: URL.urlRoot + URL.getAllLog,
            headers: {
                "Content-Type": "application/json",
                'Authorization': window.localStorage.authorization,
            }
        })
            .then(res=>{
                console.log('系统日志')
                console.log(res.data.data.logRecord)
                console.log('系统日志')
                this.setState({
                    LogData:res.data.data.logRecord,
                })
            })
    }
    changeTime=(timeData)=>{
        const date =new Date(timeData);
        return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
    }
    render(){

        // let date = new Date(time);//转换成中国标准时间:Mon Dec 10 2018 00:00:00 GMT+0800 (中国标准时间)
        // return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();

        const column = [
            {
                title1: '用户',
                title2: '时间',
                title3: '操作'
            }
        ];
        return(
            <div id="news_list">
                <div className="col-md-12 col-sm-12">
                    <h2 >用户查询记录</h2>
                </div>
                <List
                    dataSource={column}
                    renderItem={item => (
                        <List.Item>
                            <ListInfoPDFButton>{item.title1}</ListInfoPDFButton>
                            <ListInfoPDFButton>{item.title2}</ListInfoPDFButton>
                            <ListInfoPDF>{item.title3}</ListInfoPDF>
                        </List.Item>
                    )}
                />
                <List
                    pagination={5}
                    dataSource={this.state.LogData}
                    renderItem={item => (
                        <List.Item>
                            <ListInfoPDFButton>{item.username}</ListInfoPDFButton>
                            <ListInfoPDFButton>{this.changeTime(item.time)}</ListInfoPDFButton>
                            <ListInfoPDF>{item.operation}</ListInfoPDF>
                        </List.Item>
                    )}
                />
            </div>


        )
    }
}